package com.unism.uniMeterage.meterage.stream;

import java.util.Map;
public interface Manager {

    /**
     * 创建一个Worker
     * @param clazz
     * @param name
     * @param options
     * @return
     */
    public Worker createWorker(Class<?> clazz, String name,Map<String,Object> options);

    /**
     * 创建一个Worker，接着让worker开始运行
     * @param clazz
     * @param name
     * @param options
     * @return
     */
    public Worker createAndStartWorker(Class<?> clazz, String name,Map<String,Object> options);

    /**
     * 让Worker开始运行
     * @param worker
     */
    public void startWorker(Worker worker);

    /**
     * 删除指定的worker
     * @param worker
     */
    public void deleteWorker(Worker worker);

    /**
     * 将消息从一个Worker 发送到另一个Worker
     * @param message
     * @param from
     * @param to
     * @return
     */
    public Integer sendMessage(Message message, Worker from, Worker to);

    /**
     * 将消息从一个Worker 发送到同一类别的所有Worker
     * @param message
     * @param from
     * @param category
     * @return
     */
    public Integer sendMessage(Message message, Worker from, String category);

    /**
     * 初始化
     * @param options
     */
    public void initialize(Map<String, Object> options);

    /**
     * 终止manager所有工作,直到所有Woker将数据处理完为止
     */
    public void terminateAndWait();

    /**
     * 强制终止，不等待
     */
    public void terminate();

    /**
     * 获取指定类型woker数量
     * @param clazz
     * @return
     */
    public Integer getWorkerCount(Class clazz);

    /**
     * 是否存在相同Woker标识
     * @param workerName
     * @return
     */
    public Boolean existWorker(String workerName);
}
